package com.lan.enums.sys;

import lombok.Getter;
import org.apache.commons.lang.StringUtils;

import java.util.stream.Stream;


/**
 * 系统角色
 *
 * */
@Getter
public enum RoleEnum {
    SUPER_ADMIN("superAdmin", "超级管理员"),
    ADMIN("admin", "管理员"),
    USER("user", "用户"),
    STUDENT("student", "学生"),
    TEACHER("teacher", "老师");

    private final String value;
    private final String name;

    RoleEnum(final String value, final String name) {
        this.value = value;
        this.name = name;
    }

    public static String getNameByValue(final String value) {
        return Stream.of(RoleEnum.values())
                .filter(x -> StringUtils.equals(x.getValue(), value))
                .findFirst()
                .map(RoleEnum::getName)
                .orElse(null);
    }

    public static String getValueByName(final String name) {
        return Stream.of(RoleEnum.values())
                .filter(x -> StringUtils.equals(x.getName(), name))
                .findFirst()
                .map(RoleEnum::getValue)
                .orElse(null);
    }
}
